﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GCC.APIContainer.Utilities;
using GCC.Container.Abstracts;
using GCC.Container.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.DeviceServer.Models;
using System.DeviceServer.ApiModels.DeviceStatus;
namespace System.DeviceServer
{
    [ApiController]
    [Route("[controller]")]
    public class DeviceStatusServer : GCCAPIControllerBase
    {
        public DeviceStatusServer(AbsGCCContext context) : base(context)
        {
        }

        [HttpGet("devstatus/id/{id}")]
        //[GCCAuth(allowOffline: true, roles: new string[] { "admin" })]
        public DataResponse<DeviceStatusResponse> GetDeviceStatusByID([FromRoute] long id)
        {
            string key;
            if (id == 1483693598180950016)
            {
                key = "DevData_1";
            }
            else
            {
                return InvalidParameter<DeviceStatusResponse>();
            }

            string result = GCCContext.TryGet<string>(key).Result;
            Console.WriteLine("getDevData_1: {0}", result);
            var deviceStatus = System.Text.Json.JsonSerializer.Deserialize<DeviceStatusResponse>(result,
                LuanNiao.JsonConverterExtends.CommonSerializerOptions.CamelCaseChineseNameCaseInsensitive);
            if (deviceStatus is null)
            {
                return IllegalRequest<DeviceStatusResponse>();
            }
            
            return HandleData(deviceStatus);

        }
    }

}





